
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">邀请关注条件</label>
	<div class="col-sm-9 col-xs-12">
		<div class="input-group">
			<input type="text" name="random" class="form-control" value="{$item['random']}" />
			<span class="input-group-addon">次</span>
		</div>
		<span class="help-block" style="color:red;">*当邀请关注人数到达的时候获得奖励</span>
	</div>
</div>
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">邀请条件完成操作</label>
	<div class="col-sm-9 col-xs-12">
		<!--<label class='radio-inline'>
     		<input type='radio' value="0" name='sendtype' {if intval($item['sendtype'])=='0'}checked{/if}> 文本
     	</label>
		<label class='radio-inline'>
         	<input type='radio' value="1" name='sendtype' {if $item['sendtype']=='1'}checked{/if}> 图片
        </label>-->
        <label class='radio-inline'>
         	<input type='radio' value="2" name='sendtype' {if $item['sendtype']=='2'}checked{/if}> 奖励
        </label>
		<label class='radio-inline'>
         	<input type='radio' value="10" name='sendtype' {if $item['sendtype']=='10'}checked{/if}> 升级团长
        </label>
		<span class="help-block" style="color:red;">*当完成任务以后的操作</span>
	</div>
</div>
<div class="sendtype_box">
	
	
	<div id="sendtype1" {if $item['sendtype'] == 1}style="display:block;"{else}style="display:none;"{/if}>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">回复推荐者图片</label>
			<div class="col-sm-9 col-xs-12">

				<div class="input-group ">
					<input type="text" name="sendcode" value="{$item['sendcode']}" class="form-control" autocomplete="off">
					<span class="input-group-btn">
						<button class="btn btn-default" type="button" onclick="showImageDialog(this);" data-original-title="" title="">选择图片</button>
					</span>
				</div>
				<div class="input-group " style="margin-top:.5em;">
					<img src="{php echo tomedia($item['sendcode'])}" class="img-responsive img-thumbnail" width="150">
					<em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除" onclick="deleteImage(this)">×</em>
				</div>

				<span class="help-block" style="color:red;">*回复推荐者的图片、二维码</span>
			</div>
		</div>
	</div>
	<div id="sendtype2" {if $item['sendtype'] == 2}style="display:block;"{else}style="display:none;"{/if}>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">奖励推荐人</label>
			<div class="col-sm-9 col-xs-12">
				<div class="input-group">
					<div class="input-group-addon">赠送</div>
					<input type="hidden" name="rec_credit_random" value="{$item['rec_credit_random']}" placeholder="0" class="form-control" />
					<div class="input-group-addon" style="display:none;">分（积分）</div>
					<input type="text" name="rec_money_random" value="{$item['rec_money_random']}" placeholder="0.00" class="form-control" />
					<div class="input-group-addon">元（可提现余额）</div>
				</div>
			</div>
		</div>
	</div>
	<div id="sendtype10" {if $item['sendtype'] == 10}style="display:block;"{else}style="display:none;"{/if}>
		
	</div>
</div>
<div class="form-group" style="display:none;">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">推荐人通知</label>
	<div class="col-sm-9 col-xs-12">
		<textarea rows="" cols="" class="form-control"  name="scan_random_text">{$item['scan_random_text']}</textarea>
		<span class="help-block" style="color:red;">*变量：[nickname] 为扫码者昵称，例如：[nickname]有好友通过你的二维码关注了！</span>
	</div>
</div>
	
<div class="form-group" style="display:none;">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">可完成次数</label>
	<div class="col-sm-9 col-xs-12">
		<div class="input-group">
			<input type="text" name="limitrandom" value="{$item['limitrandom']}" placeholder="0" class="form-control" value="1"/>
			<div class="input-group-addon">次</div>
		</div>

		<span class="help-block" style="color:red;">*当任务完成N次之后结束任务（0为不限制次数）</span>
	</div>
</div>
<div class="form-group" style="display:none;">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">下一轮开始</label>
	<div class="col-sm-9 col-xs-12">
		<div class="input-group">
			<input type="text" name="next_active_text" value="{$item['next_active_text']}" placeholder="提示语" class="form-control" />
			<div class="input-group-addon">次</div>
		</div>
		<span class="help-block">当可完成次数大于1的时候起作用（例如：下一轮活动即可开始）</span>
	</div>
</div>


<!-- 操作海报 -->
<script language='javascript'>

	function bindEvents1(obj) {

		var index = obj.attr('index');

		var rs = new Resize(obj, {
			Max: true,
			mxContainer: "#poster1"
		});
		rs.Set($(".rRightDown", obj), "right-down");
		rs.Set($(".rLeftDown", obj), "left-down");
		rs.Set($(".rRightUp", obj), "right-up");
		rs.Set($(".rLeftUp", obj), "left-up");
		rs.Set($(".rRight", obj), "right");
		rs.Set($(".rLeft", obj), "left");
		rs.Set($(".rUp", obj), "up");
		rs.Set($(".rDown", obj), "down");
		rs.Scale = true;
		var type = obj.attr('type');
		if(type == 'nickname' || type == 'img' || type == 'title' || type == 'createtime') {
			rs.Scale = false;
		}
		new Drag(obj, {
			Limit: true,
			mxContainer: "#poster1"
		});
		$('.drag1 .remove').unbind('click').click(function() {
			$(this).parent().remove();
		})

		$.contextMenu({
			selector: '.drag1[index=' + index + ']',
			callback: function(key, options) {
				var index = parseInt($(this).attr('zindex'));

				if(key == 'next') {
					var nextdiv = $(this).next('.drag1');
					if(nextdiv.length > 0) {
						nextdiv.insertBefore($(this));
					}
				} else if(key == 'prev') {
					var prevdiv = $(this).prev('.drag1');
					if(prevdiv.length > 0) {
						$(this).insertBefore(prevdiv);
					}
				} else if(key == 'last') {
					var len = $('.drag1').length;
					if(index >= len - 1) {
						return;
					}
					var last = $('#poster1 .drag1:last');
					if(last.length > 0) {
						$(this).insertAfter(last);
					}
				} else if(key == 'first') {
					var index = $(this).index();
					if(index <= 1) {
						return;
					}
					var first = $('#poster1 .drag1:first');
					if(first.length > 0) {
						$(this).insertBefore(first);
					}
				} else if(key == 'delete') {
					$(this).remove();
				}
				var n = 1;
				$('.drag1').each(function() {
					$(this).css("z-index", n);
					n++;
				})
			},
			items: {
				"next": {
					name: "调整到上层"
				},
				"prev": {
					name: "调整到下层"
				},
				"last": {
					name: "调整到最顶层"
				},
				"first": {
					name: "调整到最低层"
				},
				"delete": {
					name: "删除元素"
				}
			}
		});
		obj.unbind('click').click(function() {
			bind1($(this));
		})

	}
	var imgsettimer = 0;
	var nametimer = 0;
	var bgtimer = 0;

	function clearTimers() {
		clearInterval(imgsettimer);
		clearInterval(nametimer);
		clearInterval(bgtimer);
	}

	function getImgUrl(val) {
		if(val.indexOf('http://') == -1) {
			val = "{$_W['attachurl']}" + val;
		}
		return val;
	}

	function bind1(obj) {
		var imgset = $('#imgset1'),
			nameset = $("#nameset1"),
			qrset = $('#qrset1');
		imgset.hide(), nameset.hide(), qrset.hide();
		clearTimers();
		var type = obj.attr('type');

		console.log(type);

		if(type == 'img') {
			imgset.show();
			var src = obj.attr('src');
			var input = imgset.find('input');
			var img = imgset.find('img');
			if(typeof(src) != 'undefined' && src != '') {
				input.val(src);
				img.attr('src', getImgUrl(src));
			}

			imgsettimer = setInterval(function() {
				if(input.val() != src && input.val() != '') {
					var url = getImgUrl(input.val());

					obj.attr('src', input.val()).find('img').attr('src', url);
				}
			}, 10);

		} else if(type == 'nickname' || type == 'createtime') {
			nameset.show();
			var color = obj.attr('color') || "#000";
			var size = obj.attr('size') || "16";
			var input = nameset.find('input:first');
			var namesize = nameset.find('#namesize1');
			var picker = nameset.find('.sp-preview-inner');
			input.val(color);
			namesize.val(size.replace("px", ""));
			picker.css({
				'background-color': color,
				'font-size': size
			});

			nametimer = setInterval(function() {
				obj.attr('color', input.val()).find('.text').css('color', input.val());
				obj.attr('size', namesize.val() + "px").find('.text').css('font-size', namesize.val() + "px");
			}, 10);

		} else if(type == 'qr') {
			qrset.show();
			var size = obj.attr('size') || "3";
			var sel = qrset.find('#qrsize');
			sel.val(size);
			sel.unbind('change').change(function() {
				obj.attr('size', sel.val())
			});
		}
	}

	$(function() {

		{if !empty($item['id'])} 
			$('.drag1').each(function() {
				bindEvents1($(this));
			}) 
		{/if}

		//改变背景
		$('#bgset1').find('button:first').click(function() {
			var oldbg = $(":input[name='poster[bg]']").val();
			bgtimer = setInterval(function() {
				var bg = $(":input[name='poster[bg]']").val();
				if(oldbg != bg) {
					bg = getImgUrl(bg);

					$('#poster1 .bg').remove();
					var bgh = $("<img src='" + bg + "' class='bg' />");
					var first = $('#poster .drag1:first');
					console.log(first);
					if(first.length > 0) {
						bgh.insertBefore(first);
					} else {
						$('#poster1').append(bgh);
					}

					oldbg = bg;
				}
			}, 10);
		})

		$('.btn-com1').click(function() {
			var imgset = $('#imgset1'),
				nameset = $("#nameset1"),
				qrset = $('#qrset1');
			imgset.hide(), nameset.hide(), qrset.hide();
			clearTimers();

			if($('#poster1 img').length <= 0) {
				alert('请选择背景图片!');
				return;
			}

			var type = $(this).data('type');
			var img = "";
			if(type == 'qr' || type == 'qrcode') {
				img = '<img src="../addons/{php echo MODULE_NAME}/static/img/qr.jpg" />';
			} else if(type == 'head') {
				img = '<img src="../addons/{php echo MODULE_NAME}/static/img/head.jpg" />';
			} else if(type == 'img' || type == 'thumb') {
				img = '<img src="../addons/{php echo MODULE_NAME}/static/img/img.jpg" />';
			} else if(type == 'nickname') {
				img = "<div class='text'>昵称</div>";
			} else if(type == 'createtime') {
				img = "<div class='text'>2018-04-22 15:30</div>";
			}
			var index = $('#poster1 .drag1').length + 1;
			var obj = $('<div class="drag drag1" type="' + type + '" index="' + index + '" style="z-index:' + index + '">' + img + '<div class="rRightDown"> </div><div class="rLeftDown"> </div><div class="rRightUp"> </div><div class="rLeftUp"> </div><div class="rRight"> </div><div class="rLeft"> </div><div class="rUp"> </div><div class="rDown"></div></div>');

			$('#poster1').append(obj);

			bindEvents1(obj);

		});

		$('.drag1').click(function() {
			bind1($(this));
		})

	})
</script>